package com.autotest.nore.service;


import com.autotest.nore.mapper.JmxScriptsMapper;
import com.autotest.nore.dto.JmxScriptsDTO;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class JmxScriptsService {

    @Autowired
    private JmxScriptsMapper jmxScriptsMapper;

    public void saveFileInfoToDatabase(String fileName, String filePath, Long uploaderId, String description, Map<String, Object> tags, long fileSize, String checksum) {
        JmxScriptsDTO jmxScriptsDTO=new JmxScriptsDTO();
        jmxScriptsDTO.setFileName(fileName);
        jmxScriptsDTO.setFilePath(filePath);
        jmxScriptsDTO.setUploaderId(uploaderId);
        jmxScriptsDTO.setDescription(description);
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            jmxScriptsDTO.setTags(objectMapper.writeValueAsString(tags)); // 将Map转换为JSON字符串
        } catch (Exception e) {
            // 处理异常
            e.printStackTrace();
        }
        jmxScriptsDTO.setFileSize(fileSize);
        jmxScriptsDTO.setChecksum(checksum);

        jmxScriptsMapper.save(jmxScriptsDTO);
    }




}
